package com.sun.handler;

import com.sun.dao.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//对添加了@controller注解的方法进行拦截处理 AOP实现
@ControllerAdvice
public class AllExceptionHandler {

    //进行一场处理，处理Exception.class类的异常
    @ExceptionHandler(Exception.class)
    @ResponseBody//不加这个会返回页面，不会返回json
    public Result doException(Exception ex){
        ex.printStackTrace();
        return Result.fail(-999,"系统异常");
    }
}
